package com.dynamic.mybatis.demo.controller;


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description
 * @Author xs
 * @Date 2023/4/6 11:10
 */
@RequestMapping("/demo/")
@RestController
public class TestController {
   /* @Autowired
    @Lazy
    private DynamicSqlSessionTemplate sqlSessionTemplate;

    @RequestMapping("/test")
    public Object test(String dmsId) {

        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("<select id=\"selectTest\" resultType=\"java.util.Map\">select now() where 1=1  <if test=\"select!=null and select!=''\"> and  2=#{select} </if></select>");
        stringBuilder.append("<update id=\"updateTest\"><if test=\"update!=null and update!=''\"> 2=2 </if></update>");
        stringBuilder.append("<insert id=\"insertTest\"><if test=\"insert!=null and insert!=''\"> 2=2 </if></insert>");
        stringBuilder.append("<delete id=\"deleteTest\"><if test=\"delete!=null and delete!=''\"> 2=2 </if></delete>");
        stringBuilder.append("<resultMap id=\"resultMapTest\" type=\"java.util.Map\"> <result column=\"id\" property=\"id\"/></resultMap>");
        //stringBuilder.append("<select id=\"selectTest2\" resultType=\"java.util.Map\">select now() where 1=1  <include refid=\"sqlTest2\"/>  <if test=\"select!=null and select!=''\"> and  2=#{select} </if></select>");
        // stringBuilder.append("<sql id=\"sqlTest2\"> and 2=2 </sql>");
        Map<String,Object> parameter = new HashMap<>();
        parameter.put("select",2);
        DynamicMappedStatement dms = new DynamicMappedStatement.Builder()
                .setId("selectTest")
                .setMappedStatement(stringBuilder.toString())
                .setResultType(Map.class.getName())
                .setReturnType(ReturnType.COLLECT)
                .setSqlCommandType(SqlCommandType.SELECT)
                .builder();
        sqlSessionTemplate.getMixedMappedStatementManager().addMappedStatement(dms);
        Object result = sqlSessionTemplate.executeTest(dms);
        System.out.println(JSON.toJSONString(result));
        return sqlSessionTemplate.execute(dmsId);
    }

    public static void main(String[] args) {

        String sql = "update user set name =1,age=1";
        List<SQLStatement> list =  SQLUtils.parseStatements(sql, JdbcConstants.MYSQL);
        for(SQLStatement ss : list){
            MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
            ss.accept(visitor);

            System.out.println(JSON.toJSONString(visitor.getColumns()));


        }
    }*/
}